package com.example.sportrecord.SQL;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class SqlBatase extends SQLiteOpenHelper {
    Context context;
    /*
         @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version
     */
    //final String name="sport";
    final static String sql="create table if not exists sport2(id integer primary key autoincrement,date varchar(20),startTime varchar(10),stopTime varchar(10),All_useTime varchar(20),explain1 varchar(10))";
    public SqlBatase(@Nullable Context context) {
        super(context, "sport2.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i("SQLite","创建数据库");
        db.execSQL(sql);
        Toast.makeText(context,"创建数据库成功",Toast.LENGTH_LONG).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //暂时不许设置
        db.execSQL("drop table if exists sport2");
        Toast.makeText(context, "即将删除数据表sport2", Toast.LENGTH_SHORT).show();
        db.execSQL("drop table if exists sport1");
        Toast.makeText(context, "即将删除数据表sport1", Toast.LENGTH_SHORT).show();
        db.execSQL("drop table if exists sport");
        Toast.makeText(context, "即将删除数据表sport", Toast.LENGTH_SHORT).show();
        onCreate(db);
    }
}
